package ControllerSelect

//
import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"test/ControllerConnct"
	"test/middleware"
	"test/models"
	"test/utils"
)

//
func Select() {
	db := ControllerConnct.Connection()
	r := gin.Default()
	r.Use(middleware.CORSMiddleware())

	//定义变量
	var studentid string
	var studentname string

	//查询学生学号以及姓名
	r.POST("/database/MBTI", func(c *gin.Context) {

		studentno = c.PostForm("stu_id")
		studentname = c.PostForm("stu_name")

		var students models.STUDENT

		err := c.ShouldBindJSON(&students)
		if err != nil {
			fmt.Println(err.Error())
		}
		result1 := db.Where("stu_id = ?", studentid).Find(&students)
		result2 := db.Where("stu_name = ?", studentid).Find(&students)
		if result1 != nil {
			fmt.Println(&result1)
		}
		if result2 != nil {
			fmt.Println(&result2)
		}
		//db.Find(&students, "student_name = ?", studentname)
		//db.Find(&students, "student_no = ?", studentno)
		c.JSON(http.StatusOK, utils.Result{
			Code:    utils.SUCCESS,
			Message: "查找成功",
		})
		//再把接收到的数据传回前端
		/*


		 */
	})
	err := r.Run(":8099")
	if err != nil {
		return
	}
	//	db.Where("student_name = ?", "put_name").Find(&struct_MBTI.Student{})
	//	db.Where("student_no = ?", "put_no").Find(&struct_MBTI.Student{})
	//	db.Where("")
}
